/*
 * TrainConnection.java
 *
 * Created on October 3, 2007, 5:56 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package drb;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Asger
 */
public class TrainConnection {
    
    public String from;
    public String to;
    public long departure;
    public long arrival;
    public int trainNumber;
    public int ecoPrice;
    public int fcPrice;
    
    public int getPrice(boolean firstClass)
    {
        return firstClass? fcPrice:ecoPrice;
    }
    
    /** Creates a new instance of TrainConnection */
    public TrainConnection() {
    }
    
    public static TrainConnection parse(ResultSet result) throws SQLException
    {
        TrainConnection con = new TrainConnection();
        con.from = result.getString("from_name");
        con.to = result.getString("to_name");
        con.departure = result.getLong("departure");
        con.arrival = result.getLong("arrival");
        con.trainNumber = result.getInt("train_number");
        con.ecoPrice = result.getInt("eco_price");
        con.fcPrice = result.getInt("fc_price");
        return con;
    }
}
